﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Presenters;

namespace University.Workshop.WinApp
{
    public partial class AddPrescriptionView : Form, IPrescription
    {

        PrescriptionPresenter presenter;
        public AddPrescriptionView()
        {
            InitializeComponent();
            presenter = new PrescriptionPresenter(this);
        }

        public AddPrescriptionView(int prescriptionId)
        {
            InitializeComponent();
            this.PrescriptionId = prescriptionId;
            presenter = new PrescriptionPresenter(this);
        }

        private void AddPrescriptionView_Load(object sender, EventArgs e)
        {

        }



        public int PrescriptionId
        {
            get
            {
                return int.Parse(txbxPrescriptionId.Text);
            }
            set
            {
                txbxPrescriptionId.Text = value.ToString();
            }
        }

        public string Medicine
        {
            get
            {
                return txbxMedicine.Text;
            }
            set
            {
                txbxMedicine.Text = value;
            }
        }

        public string Quantity
        {
            get
            {
                return txbxQuantity.Text; 
            }
            set
            {
                txbxQuantity.Text = value;
            }
        }

        public void GetMessageError(string message)
        {
            throw new NotImplementedException();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            presenter.AddMedicineToPrescription();
            PrescriptionsGridView.Refresh();
            
        }

        private void btnGenerate_Click(object sender, EventArgs e)
        {
            MessageBox.Show(presenter.GeneratePrescription());
        }

        private void txbxQuantity_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsNumber(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
            else if (Char.IsSeparator(e.KeyChar))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        public ICollection<Model.Prescription> GetPrescriptions
        {
            get
            {
                return (ICollection<Model.Prescription>)PrescriptionsGridView.DataSource;
            }
        }

        public void SetPrescriptions(ICollection<Model.Prescription> prescriptions)
        {
            PrescriptionsGridView.DataSource = prescriptions;
        }
    }
}
